public class PanDuanHuan {
    public static void main(String[] args) {
        //判断数组中有无环
        int[] nn = {1,2,1,2,7,4,3,4,1,8,7,6,9,3,4};
        // int[] nn2 = {5,7,5,6,1,8,5,3,7,0,1,4,5};
        //请大神继续优化！
        boolean flag= true;
        a:for (int i = 0; i < nn.length - 1; i++) {//定义下标
            for (int j = i + 1; j < nn.length; j++) {
                if (nn[j] == nn[i]) {
                    flag = true;
                    for (int k = 1; k <=(nn.length - 1-j ); k++) {
                        if (j-i > nn.length-1-j){
                            flag = false;
                            break;
                        }
                        if (nn[i + k] != nn[j + k]) {
                            flag = false;
                            break;
                        } else if (nn[i + k] == nn[j + k]) {
                            flag = true;
                            break a;
                        }
                    }
                } else {
                    flag = false;
                }
            }
        }
        if(flag){
            System.out.println("有环");
        }else{
            System.out.println("无环");
        }

    }
}
